﻿package kaze.net.remoting 
{
    import system.events.ActionEvent;
    
    import vegas.managers.ProtectorManager;
    import vegas.net.remoting.RemotingService;
    import vegas.net.remoting.RemotingServiceListener;
    
    /**
     * The basic implementation of the <code class="prettyprint">IRemotingEventListener</code> interface with a protector.
     */
    public class RemotingProtectorListener extends RemotingServiceListener 
    {
        /**
         * Creates a new RemotingProtectorListener instance.
         */
        public function RemotingProtectorListener(service:RemotingService = null, verbose:Boolean = true , global:Boolean = false, channel:String = null)
        {
            super( service, verbose, global, channel );
        }
        
        /**
         * The protector manager.
         */
        public var manager:ProtectorManager ;
        
        /**
         * Invoked when the service process is finished.
         */
        public override function finish( e:ActionEvent ):void
        {
            if ( manager != null )
            {
                manager.enabled = false ;
            }
            super.finish(e) ;
        } 
        
        /**
         * Invoked when the service process is started.
         */
        public override function start( e:ActionEvent ):void
        {
            if ( manager != null )
            {
                manager.enabled = true ;
            }
            super.start( e ) ;
        }
    }
}